package com.jushu.storbox.filter;

import java.io.File;

/**
 * Filters all Filter instances which are actual files
 * 
 */
public class FileFilter implements java.io.FileFilter
{
    protected String[] mFilters = null;
    
    /**
     * Sets the string file filters to use
     * 
     * @param mFilters string file filters
     */
    public FileFilter(String[] mFilters)
    {
        this.mFilters = mFilters;
    }
    
    /**
     * Return true if the given File Object is an actual file, if file filters are set in
     * the constructor, files are filtered by them
     */
    @Override
    public boolean accept(File pathname)
    {
        if (pathname.isDirectory())
        {
            return false;
        }
        
        if (pathname.getName().startsWith("."))
        {
            return false;
        }
        
        if (null != mFilters)
        {
            for (String ext : mFilters)
            {
                if (pathname.getName().endsWith(ext))
                {
                    return true;
                }
            }
        }
        else
        {
            return true;
        }
        
        return false;
    }
    
}
